<template>
    <div>
        <div class="search-con search-con-top">
            <div>
                内容：
                <Input v-model="searchData.content" style="width: 150px"></Input>
                是否处理：
                <Select style="width:150px" v-model="searchData.status">
                    <Option value="0">未处理</Option>
                    <Option value="1">已处理</Option>
                </Select>

                <Button @click="search" type="primary" icon="ios-search" style="margin-left: 10px;">搜索</Button>
                <Button @click="reset" type="warning" icon="ios-refresh" style="margin-left: 10px;">重置</Button>
            </div>
        </div>
        <br>
        <Table :columns="columns" :data="list" border stripe size="small">
            <template slot-scope="{ row , index}" slot="imgSlot">
                <show-img :imgUrl="row.img"></show-img>
            </template>
            <template slot-scope="{ row , index}" slot="makeSlot">
                <!-- <Button type="info" @click="edit(row, false)" size="small" style="margin-left: 1px;">编辑</Button> -->
                <Button type="info" @click="del(row.id)" style="margin-left: 1px;" size="small"
                    v-if="row.status == 0">已处理</Button>
            </template>
        </Table>
        <br>

        <Paginate :total="total" @on-change="changePage" @on-page-size-change="changeSize" :current="searchData.page">
        </Paginate>


        <Modal title="驾校信息" width="40" v-model="showAdd" @on-ok="editModalOk" :footer-hide="formItem.is_detail">
            <Form ref="formValidate" :model="formItem" :label-width="80">
                <FormItem label="基地">
                    <Select v-model="formItem.base_id" filterable>
                        <Option :value="val.id" v-for="val in baseList" :key="val.id">{{ val.name }}</Option>
                    </Select>
                </FormItem>
                <FormItem label="名称">
                    <Input v-model="formItem.name" placeholder=""></Input>
                </FormItem>
                <FormItem label="图片">
                    <MyUpload :maxNumber="1" @getImages="getImg" :defaultImags="[formItem.img]"></MyUpload>
                </FormItem>
                <FormItem label="联系电话">
                    <Input v-model="formItem.tel" placeholder="" />
                </FormItem>
                <FormItem label="详细地址">
                    <Input v-model="formItem.address" placeholder="" />
                </FormItem>
            </Form>
        </Modal>
    </div>
</template>

<script>
import Paginate from "_c/paginate";
import ShowImg from '_c/show_img'
import MyUpload from "_c/my-upload"
export default {
    name: "feedback",
    components: {
        Paginate, ShowImg, MyUpload
    },
    data() {
        return {
            searchData: {
                page: 1,
                limit: 10
            },
            // 列表
            columns: [
                {
                    title: '联系方式',
                    key: 'mobile',
                    align: "center"
                },
                {
                    title: '图片',
                    key: 'img',
                    align: "center",
                    slot: "imgSlot"
                },
                {
                    title: '反馈内容',
                    key: 'content',
                    align: "center"
                },
                {
                    title: '是否处理',
                    key: 'anonymity',
                    align: "center",
                    render: (h, param) => {
                        let txt = '';
                        if (param.row.status == 0) {
                            txt = '否';
                        } else {
                            txt = '是'
                        }
                        return h('div', txt);
                    }
                },
                {
                    title: '创建时间',
                    key: 'create_time',
                    align: "center"
                },
                {
                    title: '操作',
                    align: "center",
                    slot: 'makeSlot',
                },
            ],
            // 数据
            list: [],
            total: 0,
            formItem: {},
            showAdd: false,
            baseList: [],
        }
    },
    methods: {
        getImg(items) {
            items.forEach(item => {
                this.formItem.img = item.url;
            });
        },
        // 查询管理员信息
        getList() {
            this.$axios('/admin/feedback/getList', this.searchData).then(res => {
                this.list = res.data;
                this.total = res.total;
            });
        },
        search() {
            this.searchData.page = 1;
            this.getList();
        },
        reset() {
            this.searchData = {
                page: 1,
                limit: 10,
            };
            this.getList();
        },
        changePage(page) {
            this.searchData.page = page;
            this.getList();
        },
        changeSize(size) {
            this.searchData.limit = size;
            this.getList();
        },
        customSort(column, key, order) {
            this.searchData.order_by = column.key;
            this.searchData.sort = column.order;
            this.getList();
        },
        editModalOk() {
            this.$axios('/admin/school/school/save', this.formItem).then(res => {
                this.$Message.success('添加成功');
                this.showAdd = false;
                this.formItem = {};
                this.getList();
            });
        },
        edit(row, isDetail) {
            this.getBaseArr();
            if (row) {
                this.formItem = { ...row };
            } else {
                this.formItem = {
                    id: 0,
                    name: "1",
                    tel: "",
                }
            }
            this.showAdd = true;
        },
        del(id) {
            this.$axios('/admin/feedback/status', { id: id, status: 1 }).then(res => {
                this.$Message.success('执行成功');
                this.getList();
            });
        },
        getBaseArr() {
            this.$axios('/admin/school/base/getArr').then(res => {
                this.baseList = res;
            });
        },
    },
    created() {
        this.getList();
    }
}
</script>
<style src="@wangeditor/editor/dist/css/style.css"></style>
